#include "CChainItem.h"


CChainItem::CChainItem(CLComString key, CChainItem*	pFather,
    int	itemType)
{
	m_key = key;
	m_pFather = pFather;
	m_itemType = itemType;
}


CChainItem::~CChainItem()
{
	m_mapSons.clear();
}
CChainItem* CChainItem::AddSon(CLComString sID, int	itemType)
{
	CChainItem* pItem = new CChainItem(sID, this, itemType);

	m_mapSons[sID] = pItem;

	return pItem;
}

int CChainItem::AddSon(CChainItem* pSon)
{
    CLComString key = pSon->GetKey();
	if (!GetSon(key))
	{
		m_mapSons[key] = pSon;
	}
	return ECHAINITEM_RETURN_VALUE_FALSE;
}

CChainItem* CChainItem::GetSon(CLComString sID)
{
    map<CLComString, CChainItem*>::iterator it = m_mapSons.find(sID);
	if (it != m_mapSons.end())
	{
		return it->second;
	}
	return NULL;
}
CChainItem* CChainItem::GetFather()
{
	return m_pFather;
}
CLComString CChainItem::GetKey()
{
	return m_key;
}
int CChainItem::GetKeyObjType()
{
	return m_itemType;
}
void CChainItem::DelSon(CLComString sid)
{
    map<CLComString, CChainItem*>::iterator it = m_mapSons.find(sid);
	if (it != m_mapSons.end())
	{
		it->second->m_pFather = NULL;
		m_mapSons.erase(it);
	}
}
